//
//  WarningBox.m
//  IctMap
//
//  Created by songlianying on 14-3-20.
//  Copyright (c) 2014年 hongxin. All rights reserved.
//

#import "WarningBox.h"
#import "Common.h"

static ATMHud *_hud;
NSTimer *timer;

@implementation WarningBox

+ (void)userWarning:(NSString *)tips
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:tips delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

+ (void)loadTips:(NSString *)tips :(UIView *)superView
{
    if (_hud != nil)
    {
        [WarningBox removeTips];
    }
   _hud = [[ATMHud alloc] initWithDelegate:nil];
   [superView addSubview:_hud.view];
   [_hud setBlockTouches:YES];
   [_hud setCaption:tips];
   [_hud setActivity:YES];
   [_hud show];
    
}

+ (void)removeTips
{
    if (_hud != nil)
    {
        [_hud.view removeFromSuperview];
        _hud = nil;
    }
}
+ (void)showTips:(NSString *)tips :(UIView *)superView
{
  
    
    if (_hud != nil)
    {
        [WarningBox removeTips];
    }
    _hud = [[ATMHud alloc] initWithDelegate:nil];
    [superView addSubview:_hud.view];
    [_hud setBlockTouches:YES];
    [_hud setCaption:tips];
    [_hud setActivity:NO];
    [_hud show];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeshow)
                                                    userInfo:nil repeats:NO];

}

+ (void)removeshow
{
    [timer invalidate];
   
    if (_hud != nil)
    {
        [_hud.view removeFromSuperview];
        _hud = nil;
    }
}

//+ (void)backTologinPage
//{
//    LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginView];
//    loginView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//    
//    AppDelegate *app = [[UIApplication sharedApplication] delegate];
//    for (UIViewController *vc in app.tabBarController.viewControllers) {
//        [vc dismissModalViewControllerAnimated:NO];
//    }
//    for (UIView *view in app.window.subviews) {
//        [view removeFromSuperview];
//    }
//    app.window.rootViewController = nav;
//    [[NSNotificationCenter defaultCenter] postNotificationName:kNotice_Exit object:nil];
//}

//判断是否为整型
+ (BOOL)isPureInt:(NSString*)string
{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

//判断是否为浮点型
+ (BOOL)isPureFloat:(NSString*)string
{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

@end
